|
|
|
|
|
|
|
UserID, and Password properties are used for this. Next, the ODBC statement handle is established, and the ResultSetType and LockType properties are used to define the details of the connection. The statement handle is used as the unique identifier whenever you want to share data with the ODBC data source. |
|
|
|
|
|
|
|
|
You also need to disconnect the ODBC link when you exit the program. Create a new function called Disconnect and add the code in Listing 19.8. |
|
|
|
|
|
|
|
|
Listing 19.8. Coding the Disconnect method. |
|
|
|
|
|
|
|
|
Public Function Disconnect()
'
' disconnect from the data source
'
Dim intResult As Integer
'
' Deallocate statement handle:
If hStmt <> 0 Then
intResult = SQLFreeStmt(hStmt, sqlDrop)
If intResult <> sqlSuccess Then
Err.Raise vbObjectError + 6, App.EXEName, "Unable to free statement
handle"
Disconnect = intResult
End If
End If
'
' Disconnect
If hDbc <> 0 Then
intResult = SQLDisconnect(hDbc)
If intResult <> sqlSuccess Then
Err.Raise vbObjectError + 7, App.EXEName, "Unable to disconnect from
data source"
Disconnect = intResult
End If
End If
'
' Deallocate connection handle
If hDbc <> 0 Then
intResult = SQLFreeConnect(hDbc)
If intResult <> sqlSuccess Then
Err.Raise vbObjectError + 8, App.EXEName, "Unable to deallocate
connection handle"
Disconnect = intResult
End If
End If
'
DeallocateEnv
'
Disconnect = sqlSuccess
'
End Function |
|
|
|
|
|